<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="bean.Cart" %>
<%@page import="dao.Cartdao" %>
<%@ page import="dao.Bookdao" %>
<%@ page import="bean.Book" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style>
        .clear {
            font-family: sans-serif;
            background-color: #FF7F50;
            text-decoration: none;
            color: Aquamarine;
            width: 150px;
            height: 30px;
            border-color: black;
            border-style: solid;
            border-width: 1px;
            text-align: center;
            vertical-align: middle;
            padding: 5px;
            margin-left: 1200px;
            margin-bottom: 20px;
        }
        .op {
            font-family: Consolas;
            font-size: 15px;
            background-color: #FF7F50;
            text-decoration: none;
            width: 70px;
            height: 40px;
            border-color: black;
            border-style: solid;
            border-width: 1px;
            text-align: center;
            vertical-align: middle;
        }
        .tdwidth {
            width: 200px;
            height: 40px;
            background-color: #FF7F50;
            color: black;
        }
        #cartfont {
            font-family: serif;
            font-size: 40px;
            color:orange;
            text-align: center;
        }
        a#over:link, a#over:visited {
            font-family: sans-serif;
            background-color: #FF7F50;
            text-decoration: none;
            float: right;
            color: Aquamarine;
            width: 150px;
            height: 30px;
            border-color: black;
            border-style: solid;
            border-width: 1px;
            text-align: center;
            vertical-align: middle;
            margin-right: 50px;
            margin-bottom: 50px;
        }
        a#over:hover, a#over:active {
            background-color: red;
        }
    </style>
</head>
<body>
<jsp:include page="head.jsp"></jsp:include>
<jsp:include page="browse.jsp"></jsp:include>

<%
    Cartdao cartdao = new Cartdao();
    String username = (String)session.getAttribute("name");
    ArrayList<Cart> arrayList = cartdao.getAllItems(username);
    int rownum = arrayList.size();
    double sumprice = cartdao.getSumPrice(username);
%>

<p id="cartfont" style="margin-top: 50px;">购物车</p>
<p style="margin-left: 650px;"> 总价：<% out.print(sumprice); %> </p>
<form action="clearCart" method="post">
    <input class="clear" type="submit" value="清空购物车">
</form>
<table border="1" id="cartable" style="border-collapse: collapse;" align="center">
    <tr>
        <td class="tdwidth">商品信息</td>
        <td class="tdwidth">单价</td>
        <td class="tdwidth">数量</td>
        <td class="tdwidth">金额</td>
        <td class="tdwidth">操作</td>
    </tr>
    <%
        for(int i = 0; i < rownum; i++) {
            out.print("<tr>");
            Cart cart = arrayList.get(i);
            String isbn = cart.getIsbn();
            Bookdao bookdao = new Bookdao();
            Book book = bookdao.getBook(isbn);
            out.print("<td><a href=\"abook.jsp?id=" +book.getIsbn() + "\" target=\"_blank\">");
            out.print("<img width=200px height=200px src="+cart.getBooksrc()+">");
            out.print("</a></td>");
            out.print("<td> ￥"+cart.getBookprice()+"</td>");
            out.print("<td> "+cart.getNum()+"本</td>");
            out.print("<td> ￥"+cart.getNum()*cart.getBookprice()+"</td>");
            out.print("<td>");
            out.print("<form action='addCart' method='post'>");
            out.print("<input type='hidden' name='id' value="+isbn+">");
            out.print("<input type='hidden' name='type' value='cart'>");
            out.print("<input class='op' type='submit' value='+'>   加一");
            out.print("</form>");

            out.print("<form action='deleteOneCart' method='post'>");
            out.print("<input type='hidden' name='id' value="+isbn+">");
            out.print("<input class='op' type='submit' value='-'>   减一");
            out.print("</form>");

            out.print("<form action='deleteAllCart' method='post'>");
            out.print("<input type='hidden' name='id' value="+isbn+">");
            out.print("<input class='op' type='submit' value='remove'>   删除");
            out.print("</form>");
            out.print("</td>");
            out.print("</tr>");
        }
    %>
</table>
<form action="/Web/pay">
    <input type="text" name="addr" value="" style="margin-top: 10px; margin-left: 580px; width: 200px; height: 30px;"> 填写地址
    <input class="clear" type="submit" value="结算">
</form>
</body>
</html>